//
//  ActivityModel.m
//  RainbowFM
//
//  Created by chenli on 14/12/27.
//  Copyright (c) 2014年 RB. All rights reserved.
//

#import "ActivityModel.h"
#import "ActivityAPI.h"
#import "LoginModel.h"

@implementation ActivityModel

+(instancetype)sharedModel
{
    static ActivityModel *activityModel = nil;
    static dispatch_once_t once;
    
    dispatch_once(&once, ^{
        activityModel = [[ActivityModel alloc] init];
    });
    
    return activityModel;
}

-(void)fetchActivityListWithPage:(NSInteger)page result:(void (^)(BOOL, NSArray *))res{
    ActivityAPI *api = [[ActivityAPI alloc] init];
    [api fetchActivityListWithUserID:[LoginModel sharedModel].userID actStateID:@"0" actCategoryID:@"0" currentPage:[NSString stringWithFormat:@"%d",page] pageSize:@"100" result:^(NSArray *array, NSString *msg) {
        NSMutableArray *listArray = [NSMutableArray array];
        for (NSDictionary *dict in array) {
            [listArray addObject:[[ActivityListItem alloc] initWithAttributes:dict]];
        }
        
        res(YES,listArray);
    }];
}


-(void)fetchActivityDetailWithID:(NSString *)actiId result:(void (^)(BOOL, ActivityDetailItem *,NSString *))res{
    ActivityAPI *api = [[ActivityAPI alloc] init];
    [api fetchActivityDetailWithActID:actiId userID:[LoginModel sharedModel].userID result:^(NSDictionary *dict, NSString *msg) {
        if (dict != nil) {
            res(YES,[[ActivityDetailItem alloc] initWithAttributes:dict],@"");
        }else{
            res(NO,nil,msg);
        }
        
    }];
}

-(void)userApplyWithActID:(NSString *)actId voteName:(NSString *)name sex:(NSString *)sex_ tel:(NSString *)tel result:(void (^)(BOOL, NSString *))res{
    ActivityAPI *api = [[ActivityAPI alloc] init];
    [api applyManageWithOper:@"1" actID:actId userID:[LoginModel sharedModel].userID voteName:name sex:sex_ tel:tel result:^(BOOL success) {
        if (success) {
            res(YES,@"提交成功");
        }else{
            res(NO,@"失败");
        }
    }];
}


-(void)fetchPrizeList:(void (^)(BOOL, NSArray *))result{
    ActivityAPI *api = [[ActivityAPI alloc] init];
    [api fetchPrizeListWithUserID:[LoginModel sharedModel].userID == nil ? @"" : [LoginModel sharedModel].userID
                      currentPage:@"1"
                         pageSize:@"100"
                           result:^(NSArray *array, NSString *msg) {
        NSMutableArray *listArray = [NSMutableArray array];
        for (NSDictionary *dict in array) {
            [listArray addObject:[[PrizeListItem alloc] initWithAttributes:dict]];
        }
        
        result(YES,listArray);
    }];
}


-(void)fetchMyPrizeListWithPage:(NSInteger)page result:(void (^)(BOOL, NSArray *))res{
    ActivityAPI *api = [[ActivityAPI alloc] init];
    [api fetchMyPrizeListWithUserID:[LoginModel sharedModel].userID
                        currentPage:[NSString stringWithFormat:@"%d",page]
                           pageSize:@"1000"
                             result:^(NSArray *array, NSString *msg) {
                                 if (array != nil) {
                                     NSMutableArray *listArray = [NSMutableArray array];
                                     for (NSDictionary *dict in array) {
                                         [listArray addObject:[[MyPrizeListItem alloc] initWithAttributes:dict]];
                                     }
                                     
                                     res(YES,listArray);
                                 }else{
                                     res(NO,nil);
                                 }
                             }];
}


-(void)fetchPrizeDetailWithActID:(NSString *)actId result:(void (^)(BOOL, PrizeDetailItem *))res{
    ActivityAPI *api = [[ActivityAPI alloc] init];
    [api fetchPrizeDetailWithUserID:[LoginModel sharedModel].userID actID:actId result:^(NSDictionary *dict, NSString *msg) {
        if (dict != nil) {
            res(YES,[[PrizeDetailItem alloc] initWithAttributes:dict]);
        }
    }];
}


-(void)fetchExchangeDetailWithExchID:(NSString *)exchId result:(void (^)(BOOL, id, NSString *))res{
    ActivityAPI *api = [[ActivityAPI alloc] init];
    [api fetchExchangeDetailWithExchID:exchId
                                userID:[LoginModel sharedModel].userID
                                result:^(NSDictionary *dict, NSString *msg) {
                                    
                                }];
}


-(void)submitQuestionWithActID:(NSString *)actId ansContent:(NSString *)content result:(void (^)(BOOL, NSString *))res{
    ActivityAPI *api = [[ActivityAPI alloc] init];
    [api submitQuestionWithWithActID:actId
                              userID:[LoginModel sharedModel].userID
                          ansContent:content
                              result:^(NSArray *array, NSString *msg) {
                                  if (array != nil) {
                                      
                                  }else{
                                      res(NO,msg);
                                  }
                          }];
}

@end


@implementation ActivityListItem

-(instancetype)initWithAttributes:(NSDictionary *)attributes{
    self = [super init];
    if (!self) {
        return nil;
    }
    
    _actId      = attributes[@"actId"];
    _actName    = attributes[@"actName"];
    _actStatus  = attributes[@"actStatus"];
    _actTypeId  = attributes[@"actTypeId"];
    _content    = attributes[@"content"];
    _endTime    = attributes[@"endTime"];
    _pic        = attributes[@"pic"];
    _signupFlag = attributes[@"signupFlag"];
    _startTime  = attributes[@"startTime"];
    
    
    
    return self;
}

@end

@implementation ActivityDetailItem

-(instancetype)initWithAttributes:(NSDictionary *)attributes{
    self = [super init];
    if (!self) {
        return nil;
    }
    
    _actName     = attributes[@"actName"];
    _actRule     = attributes[@"actRule"];
    _bannerPic   = attributes[@"bannerPic"];
    _bannerVideo = attributes[@"bannerVideo"];
    _startTime = attributes[@"startTime"];
    _endTime     = attributes[@"endTime"];
    _isBannerPic = attributes[@"isBannerPic"];
    _isFirst     = attributes[@"isFirst"];
    _signupFlag  = attributes[@"signupFlag"];
    _signupItem  = attributes[@"signupItem"];
    
    
    
    return self;
}

@end


@implementation PrizeListItem

-(instancetype)initWithAttributes:(NSDictionary *)attributes{
    self = [super init];
    if (!self) {
        return nil;
    }
    
    _actStatus = attributes[@"actStatus"];
    _actId     = attributes[@"actId"];
    _expireDt     = attributes[@"expireDt"];
    _prizeDesc   = attributes[@"prizeDesc"];
    _prizeHitRate = attributes[@"prizeHitRate"];
    _prizeId     = attributes[@"prizeId"];
    _prizeLeftNum = attributes[@"prizeLeftNum"];
    _prizeName     = attributes[@"prizeName"];
    _prizeTotalNum  = attributes[@"prizeTotalNum"];
    _prizeUrl  = attributes[@"prizeUrl"];
    _qstFlag = attributes[@"qstFlag"];
    
    
    
    return self;
}

@end


@implementation PrizeDetailItem

-(instancetype)initWithAttributes:(NSDictionary *)attributes{
    self = [super init];
    if (!self) {
        return nil;
    }
    
    _actId      = attributes[@"actId"];
    _qstId      = attributes[@"qstId"];
    _qstName    = attributes[@"qstName"];
    _qstContent = attributes[@"qstContent"];
    _qstAnsOpt  = attributes[@"qstAnsOpt"];
    _prizeId    = attributes[@"prizeId"];
    _prizeName  = attributes[@"prizeName"];
    _prizeUrl   = attributes[@"prizeUrl"];
    _prizeDesc  = attributes[@"prizeDesc"];
    _endDt      = attributes[@"endDt"];
    
    
    
    return self;
}

@end


@implementation MyPrizeListItem



@end